<template>
  <div class="app-container">
    <el-card style="border-radius: 10px;">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工单编码" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入工单编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="产品编号" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入产品编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产商" prop="manufactureName">
        <el-input
          v-model="queryParams.manufactureName"
          placeholder="请输入生产商"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <el-card style="border-radius: 10px;margin-top: 15px">
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :header-cell-style="{textAlign:'center'}" :cell-style="{textAlign:'center'}" :data="outsourcingList" @selection-change="handleSelectionChange">
      <el-table-column label="工单编码" width="130" prop="workorderCode">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">{{ scope.row.workorderCode }}</el-button>
        </template>
      </el-table-column>

      <el-table-column label="订单编号" prop="orderCode" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="产品编号"  prop="productCode" :show-overflow-tooltip="true"/>
      <el-table-column label="产品名称"  prop="productName" :show-overflow-tooltip="true"/>
      <el-table-column label="规格型号" width="150" prop="productSpc" :show-overflow-tooltip="true"/>
      <el-table-column label="单位" width="60"  prop="unitOfMeasure"/>
      <el-table-column label="需求日期" prop="requestDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="计划开工时间" align="center" width="120px" prop="startDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划完工时间" align="center" width="120px" prop="endDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="生产商编码" prop="manufactureCode" :show-overflow-tooltip="true"/>
      <el-table-column label="生产商"  prop="manufactureName"  :show-overflow-tooltip="true"/>
      <el-table-column  label="工单数量"   prop="quantity">
        <template slot-scope="scope">
          <el-tag type="danger">{{ scope.row.quantity }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="合格品数量"prop="quantityQualified"  :show-overflow-tooltip="true"/>
      <el-table-column fixed="right" label="状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_outsource_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"

        width="200px"
        class-name="small-padding fixed-width"
        >
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-s-check"
            v-if="scope.row.status == 'PREPARE'&&scope.row.attr2=='Y'"
            @click="handleGoQc(scope.row)"
            v-has-permi="['pro:outsourcing:goQc']"
          >质检</el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-finished"
            v-if="scope.row.status == 'PREPARE'"
            @click="handleFinish(scope.row)"
            v-has-permi="['pro:outsourcing:goQc']"
          >完成</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改生产工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="工单编号">
              <el-input v-model="form.workorderCode" readonly placeholder="请输入工单编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工单名称">
              <el-input v-model="form.workorderName" readonly placeholder="请输入工单名称"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row >
          <el-col :span="12">
            <el-form-item label="订单编号">
              <el-input v-model="form.orderCode" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单名称">
              <el-input v-model="form.orderName" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="生产工单号">
              <el-input v-model="form.orderCode" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产工单名称">
              <el-input v-model="form.orderName" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="产品编号">
              <el-input v-model="form.productCode" readonly placeholder="请选择产品"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品名称">
              <el-input v-model="form.productName" placeholder="请选择产品" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="规格型号">
              <el-input v-model="form.productSpc" placeholder="请选择产品" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位">
              <el-input v-model="form.unitOfMeasure" placeholder="请选择产品" readonly/>
            </el-form-item>
          </el-col>
        </el-row>

<!--    <el-row>
          <el-col :span="12">
            <el-form-item label="计划开工日期">
              <el-date-picker
                clearable
                readonly
                v-model="form.startDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择计划开工日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划完工日期">
              <el-date-picker
                clearable
                readonly
                v-model="form.endDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择计划完工日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="工单数量">
              <el-input-number :min="1" v-model="form.quantity" disabled placeholder="请输入生产数量"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="需求日期" prop="requestDate">
              <el-date-picker
                clearable
                readonly
                v-model="form.deadline"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择需求日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="单据状态" prop="status">
              <el-select v-model="form.status" disabled placeholder="请选择单据状态">
                <el-option
                  v-for="dict in dict.type.mes_outsource_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col></el-col>
          <el-col></el-col>
          <el-col></el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" readonly placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs type="border-card"  v-model="activeTab">
        <el-tab-pane v-if="form.bomId!=null" label="BOM结构" name="first">
          <el-table
            v-if="refreshTable"
            v-loading="treeLoading"
            :data="treeList"
            row-key="id"
            :default-expand-all="true"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          >
            <el-table-column
              label="产品/物料名称"
              width="200"
              align="left"
              prop="itemName"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="产品/物料编号"
              width="140"
              align="center"
              prop="itemCode"
              :show-overflow-tooltip="true"
            />
            <el-table-column label="物料类型" width="120" align="center" prop="itemType" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.mes_item_product" :value="scope.row.itemType" />
              </template>
            </el-table-column>
            <el-table-column label="规格型号" align="center" prop="specification" :show-overflow-tooltip="true" />
            <el-table-column label="单位" align="center" prop="unitOfMeasure" :show-overflow-tooltip="true" />
            <el-table-column
              v-for="col in columnsConfig"
              :key="col.prop"
              :label="col.label"
              :prop="col.prop"
              :width="col.width"
              :align="col.align"
              v-if="col.show">
            </el-table-column>
            <el-table-column label="bom编号" width="200" align="center" prop="bomCode" :show-overflow-tooltip="true" />
            <el-table-column label="bom版本" width="120" align="center" prop="bomName" :show-overflow-tooltip="true" />
            <el-table-column label="图纸编号" width="140" align="center" prop="drawCode" :show-overflow-tooltip="true"/>
            <el-table-column label="使用量" align="center" prop="used" />
            <!--            <el-table-column label="使用比例" align="center" prop="proportional" />-->
            <el-table-column label="规格" align="center" prop="model" :show-overflow-tooltip="true"/>
            <el-table-column label="规格单位" align="center" width="80" prop="specificationUnit"/>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="物料清单" v-if="form.bomId!=null" name="bomItem">
          <div >
            <el-table border v-loading="false" :data="itemList" >
              <el-table-column type="index" label="序号" width="55" align="center"/>
              <el-table-column label="物料编码" align="center" prop="itemCode" :show-overflow-tooltip="true"/>
              <el-table-column label="物料名称" align="center" prop="itemName" :show-overflow-tooltip="true"/>
              <el-table-column label="规格型号" align="center" prop="specification" :show-overflow-tooltip="true"/>
              <el-table-column label="单位" width="100px" align="center" prop="unitOfMeasure" :show-overflow-tooltip="true"/>
              <el-table-column label="需求数量" width="120px" align="center" prop="used" :show-overflow-tooltip="true"/>
              <!--              <el-table-column label="用料比例" width="100px" align="center" prop="proportional"/>-->
              <el-table-column label="规格" align="center" prop="model" :show-overflow-tooltip="true"/>
              <el-table-column label="规格单位" align="center" width="80" prop="specificationUnit"/>
              <el-table-column
                v-for="col in columnsConfig"
                :key="col.prop"
                :label="col.label"
                :prop="col.prop"
                :width="col.width"
                :align="col.align"
                v-if="col.show">
              </el-table-column>
            </el-table>
            <pagination
              v-show="itemTotal>0"
              :total="itemTotal"
              :page.sync="itemQueryParams.pageNum"
              :limit.sync="itemQueryParams.pageSize"
              @pagination="getBomItemList"
            />
          </div>
        </el-tab-pane>
        <el-tab-pane label="BOM图纸" v-if="form.bomId!=null">
          <li :key="file.drawUrl" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList">
            <el-link :href="`${file.drawUrl}`" :underline="false" target="_blank">
              <span class="el-icon-document"> {{ getFileName(file.drawUrl) }} </span>
            </el-link>
          </li>
        </el-tab-pane>
        <el-tab-pane label="BOM工序图纸" name="processPicture" v-if="form.bomId!=null">
          <el-tabs type="border-card">
            <el-tab-pane v-for="(process,index) in processOptions" :key="index" :label="process.processName">
              <PDFView
                :processId="process.processId"
                :bomId="form.bomId"></PDFView>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane label="质检信息" name="qcList">
          <el-table border v-loading="false" :data="form.qcList" >
            <el-table-column label="检验单编号" align="center" prop="osqcCode" width="120"/>
            <el-table-column label="检验日期" align="center" prop="inspectDate" width="120"/>
            <el-table-column label="检验人" align="center" prop="inspector"/>
            <el-table-column label="本次接收数量" align="center" prop="quantityRecived"/>
            <el-table-column label="本次检测数量" align="center" prop="quantityCheck"/>
            <el-table-column label="不合格品数量" align="center" prop="quantityUnqualified"/>
            <el-table-column label="检测结果" width="90px" align="center" prop="checkResult" >
              <template slot-scope="scope">
                <dict-tag :options="dict.type.mes_qc_result" :value="scope.row.checkResult"/>
              </template>
            </el-table-column>
            <el-table-column label="不良品处理状态" align="center" prop="qcUnqualifiedRecord.disposeStatus"/>
            <el-table-column label="让步接收数量" align="center" prop="qcUnqualifiedRecord.itemRecptNum"/>
            <el-table-column label="退回数量" align="center" prop="qcUnqualifiedRecord.chargebackNum"/>
            <el-table-column label="报废数量" align="center" prop="qcUnqualifiedRecord.scrapNum"/>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel" v-if="(optType == 'view' || form.status != 'PREPARE') && optType != 'finish'">返 回</el-button>
<!--        <el-button type="primary" @click="submitForm" v-if="form.status == 'PREPARE' && optType != 'view'">保 存</el-button>-->
        <el-button type="primary" @click="handDofinish" v-if="optType == 'finish'" v-has-permi="['pro:outsourcing:edit']">完 工</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="送检信息单" :visible.sync="qcOpen" width="500px" append-to-body>
      <el-form ref="qcForm" :model="qcForm" :rules="qcRules" label-width="80px">
<!--        <el-form-item label="工单编码" prop="workorderCode">
          <el-input v-model="qcForm.workorderCode" placeholder="请输入工单编码" />
        </el-form-item>-->
        <el-form-item label="送检数量" prop="quantityRecived">
          <el-input-number :min="0.01" :step="0.01" :precision="2" :max="qcForm.max || Infinity" v-model="qcForm.quantityRecived" placeholder="请输入送检数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitQcForm">确 定</el-button>
        <el-button @click="cancelQc">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  delOutsourcing,
  getMdDrawByBomId,
  getOutsourcing,
  listOutsourcing,
  updateOutsourcing,
  addOutsourcingQc,
  goOutsourcingQc
} from "@/api/mes/pro/outsourcing";
import ProTask from "@/views/mes/pro/workticket/task/proTask.vue";
import WorkTicketItem from "@/views/mes/pro/workticket/items/item.vue";
import { getBomGl } from "@/api/mes/md/bomgl";
import { listBomProcess } from "@/api/mes/pro/routeprocess";
import PlanBom from "@/views/mes/pro/planning/bom/bom.vue";
import ProcessPicture from "@/views/mes/md/bomgl/processPicture.vue";
import PDFView from "@/views/mes/md/bomgl/pdfView.vue";
import BomItem from "@/views/mes/md/bomgl/bomItem.vue";
import { listItem, listTree } from "@/api/mes/md/bomItem";
import { parseTime } from "@/utils/ruoyi";
import Template from "@/views/print/printtemplate/list.vue";
import {getColumnsConfigKey} from "@/api/system/columnsconfig";

export default {
  name: "Outsourcing",
  components: {Template, BomItem, PDFView, ProcessPicture, PlanBom, WorkTicketItem, ProTask},
  dicts: ['mes_outsource_status', 'mes_workorder_sourcetype', 'mes_workorder_type','mes_outsource_status','mes_outsource_type','mes_qc_result'],
  data() {
    return {
      columnsConfig:[],
      // 重新渲染表格状态
      refreshTable: true,
      // BOM结构
      treeLoading: true,
      // BOM结构数据
      treeList: [],
      // 工艺物料回显开关
      refresh: false,
      fileList:[{drawUrl:''}],
      // 工序列表
      processOptions: [],
      activeProcess: 0,
      optType: undefined,
      // 遮罩层
      loading: true,
      activeTab:"first",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产工单--外协表格数据
      outsourcingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      qcOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchStatus:['PREPARE','FINISHED'],
        workorderCode: null,
        workorderName: null,
        productId: null,
        productCode: null,
        productName: null,
        manufactureCode: null,
        manufactureName: null,
        planCode: null,
        planName: null,
        bomId: null,
        bomCode: null,
        bomName: null,
      },
      // 物料表格数据
      itemList: [],
      // 物料总条数
      itemTotal: 0,
      itemQueryParams: {
        pageNum: 1,
        pageSize: 10,
        parentId: null,
      },
qcForm: {
        workorderCode: null,
        quantityRecived: null,
  max:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      qcRules: {
        quantityRecived: [
          {required: true, message: "送检数不能为空", trigger: "blur"}
        ],
      },
      // 表单校验
      rules: {
        workorderCode: [
          {required: true, message: "工单编码不能为空", trigger: "blur"}
        ],
        workorderName: [
          {required: true, message: "工单名称不能为空", trigger: "blur"}
        ],
        orderSource: [
          {required: true, message: "来源类型不能为空", trigger: "blur"}
        ],
        productId: [
          {required: true, message: "产品ID不能为空", trigger: "blur"}
        ],
        productCode: [
          {required: true, message: "产品编号不能为空", trigger: "blur"}
        ],
        productName: [
          {required: true, message: "产品名称不能为空", trigger: "blur"}
        ],
        unitOfMeasure: [
          {required: true, message: "单位不能为空", trigger: "blur"}
        ],
        quantity: [
          {required: true, message: "生产数量不能为空", trigger: "blur"}
        ],
        parentId: [
          {required: true, message: "父工单不能为空", trigger: "blur"}
        ],
        ancestors: [
          {required: true, message: "所有父节点ID不能为空", trigger: "blur"}
        ],
        requestDate: [
          {required: true, message: "需求日期不能为空", trigger: "blur"}
        ],
        planCode: [
          {required: true, message: "计划编码不能为空", trigger: "blur"}
        ],
        planName: [
          {required: true, message: "计划名称不能为空", trigger: "blur"}
        ],
        bomId: [
          {required: true, message: "BOM ID不能为空", trigger: "blur"}
        ],
        bomCode: [
          {required: true, message: "BOM编码不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getItemBase();
  },
  methods: {
    parseTime,
    // 根据bomID获取树形结构
    getTree() {
      let bomId = this.form.bomId;
        listTree(bomId).then(response => {
          this.treeList = this.handleTree(response.data, 'bomId', 'parentId');
          this.treeLoading = false;
        })
    },
    getItemBase(){
      getColumnsConfigKey('MdItem_Base').then(res=>{
        this.columnsConfig = JSON.parse(res.data);
      })
    },
     // 获取文件名称
    getFileName(name) {
      if (name.lastIndexOf("/") > -1) {
        return name.slice(name.lastIndexOf("/") + 1);
      } else {
        return "";
      }
    },
    /** 查询生产工单--外协列表 */
    getList() {
      this.loading = true;
      listOutsourcing(this.queryParams).then(response => {
        this.outsourcingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取物料组成列表
    getBomItemList() {
        this.itemQueryParams.parentId = this.form.bomId;
        listItem(this.itemQueryParams).then(response => {
          if (response.code == 200 && response.rows) {
            this.itemList = response.rows.map((item) => {
              item.used = (item.used * this.form.quantity).toFixed(2);
              return item;
            })
            this.itemTotal = response.total;
          }
        })
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    cancelQc(){
      this.qcOpen=false;
    },
    // 表单重置
    reset() {
      this.form = {
        workorderId: null,
        workorderCode: null,
        workorderName: null,
        workorderType: null,
        orderSource: null,
        sourceCode: null,
        productId: null,
        productCode: null,
        productName: null,
        productSpc: null,
        unitOfMeasure: null,
        quantity: null,
        quantityProduced: null,
        quantityChanged: null,
        quantityScheduled: null,
        clientId: null,
        clientCode: null,
        clientName: null,
        vendorId: null,
        vendorCode: null,
        vendorName: null,
        beginDate: null,
        finishDate: null,
        parentId: null,
        ancestors: null,
        startDate: null,
        endDate: null,
        requestDate: null,
        status: "0",
        batchCode: null,
        remark: null,
        attr1: null,
        attr2: null,
        attr3: null,
        attr4: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        planCode: null,
        planName: null,
        bomId: null,
        bomCode: null,
        bomName: null,
        tenantId: null,
        qcList:[]
      };
      this.resetForm("form");
      this.activeTab='first';
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查询明细按钮操作
    handleView(row) {
      this.reset();
      const workorderId = row.workorderId || this.ids;
      this.getOutsourcingView(workorderId,'查看工单信息','view')
    },
    getOutsourcingView(workorderId,title,optType){
      getOutsourcing(workorderId).then(response => {
        this.form = response.data;
          if(this.form.bomId) {
            getMdDrawByBomId(this.form.bomId).then(re => {
              this.fileList = re.data;
            })
            this.getTree();
            // this.getBom();
            this.getProcess();
            this.getBomItemList();
          }else{
            this.activeTab='qcList'
          }
        this.open = true;
        this.title = title;
        this.optType =optType;
      });
    },
    handleGoQc(row){
      goOutsourcingQc(row.workorderCode).then(response => {
        this.qcForm.max=response.data.max||Number.MAX_VALUE;
        this.qcForm.quantityRecived=response.data.quantityRecived;
        this.qcForm.workorderCode=row.workorderCode;
        this.qcOpen = true;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.workorderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },


    /** 提交按钮 */
    submitForm() {
      this.$refs[ "form" ].validate(valid => {
        if (valid) {
          if (this.form.workorderId != null) {
            updateOutsourcing(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            /*addOutsourcing(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });*/
          }
        }
      });
    },
    /** 提交按钮 */
    submitQcForm() {
      this.$refs[ "qcForm" ].validate(valid => {
        if (valid) {
          addOutsourcingQc(this.qcForm).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.qcOpen = false;
              this.getList();
            });
          }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workorderIds = row.workorderId || this.ids;
      this.$modal.confirm('是否确认删除外协工单编号为"' + workorderIds + '"的数据项？').then(function () {
        return delOutsourcing(workorderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pro/outsourcing/export', {
        ...this.queryParams
      }, `outsourcing_${new Date().getTime()}.xlsx`)
    },
    // 完成按钮操作
    handleFinish(row) {
      this.reset();
      this.getOutsourcingView(row.workorderId,'查看工单信息','finish');
    },
   /* handleConfirm(row) {
      let that = this;
      that.$modal.confirm('是确认完成生产任务编制？【确认后将不能更改】').then(function () {
        that.form.status = 'CONFIRMED';
        that.form.workorderId = row.workorderId;
        that.form.quantity = null;
        updateWorkorder(that.form).then(response => {
          that.$modal.msgSuccess('修改成功');
          that.getList();
        });
      })
        .catch(() => {
        });
    },*/
    handDofinish() {
      let f={status:'FINISHED',workorderId:this.form.workorderId}
      let that = this;
      this.$modal
        .confirm('确认完成工单？一旦完成，此工单将无法再质检、入库')
        .then(function () {
          updateOutsourcing(f).then(response => {
            that.getList();
            that.open = false;
            that.$modal.msgSuccess('操作成功');
            })
        })
        .catch(() => {
        });
    },
    getBom() {
      getBomGl(this.form.bomId).then(response => {
        this.bom = response.data;
      });
    },
    //获取当前产品对应的生产工序
    getProcess() {
      listBomProcess(this.form.bomId).then(response => {
        this.processOptions = response.data;
      });
    },
    //Step点击
    handleStepClick(index) {
      this.activeProcess = index;
    }
  }
};
</script>
